CI/CD & DevOps Guide

The DevOps Revolution

DevOps is a set of practices that combines software development (Dev) and IT operations (Ops). It aims to shorten the systems development life cycle and provide continuous delivery with high software quality. CI/CD is the backbone of the modern DevOps environment.

Core CI/CD Concepts

Continuous Integration (CI)

The practice of automating the integration of code changes from multiple contributors into a single software project. Developers merge their changes back to the main branch as often as possible. Each merge triggers an automated build and test sequence.

Continuous Delivery (CD)

An extension of CI where code changes are automatically built, tested, and prepared for a release to production. It expands upon CI by deploying all code changes to a testing and/or production environment after the build stage.

Continuous Deployment (CD)

A further step where every change that passes all stages of your production pipeline is released to your customers. There's no human intervention, and only a failed test will prevent a new change from being deployed to production.

The CI/CD Pipeline

A CI/CD pipeline is a series of steps that must be performed in order to deliver a new version of software. It's a manifestation of the "path to production."

Commit

Build

Test

Package

Deploy

Essential DevOps Tools

Jenkins

An open-source automation server that enables developers to reliably build, test, and deploy their software. Highly extensible with thousands of plugins.

GitHub Actions

Automate, customize, and execute your software development workflows right in your GitHub repository. You can discover, create, and share actions to perform any job you'd like.

GitLab CI/CD

A part of GitLab, it provides a complete CI/CD toolchain out-of-the-box. It's known for its tight integration with the GitLab ecosystem.

Docker

A platform for developing, shipping, and running applications in containers. Containers package up code and all its dependencies, ensuring the application works reliably in any computing environment.

Kubernetes

An open-source system for automating deployment, scaling, and management of containerized applications. It groups containers that make up an application into logical units for easy management.

Terraform

An infrastructure as code (IaC) tool that lets you build, change, and version infrastructure safely and efficiently. It can manage existing and popular service providers as well as custom in-house solutions.

Example: GitHub Actions Workflow

Here is a simple example of a GitHub Actions workflow file (e.g., `.github/workflows/ci.yml`) for a Node.js project. This workflow triggers on every push to the `main` branch.


name: Node.js CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [16.x, 18.x, 20.x]

    steps:
    - name: Checkout repository
      uses: actions/checkout@v3

    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'

    - name: Install dependencies
      run: npm ci

    - name: Run tests
      run: npm test
            

This workflow defines a single job, `build`, that runs on an Ubuntu environment. It tests the project against three different Node.js versions. The steps check out the code, set up the specified Node.js version, install dependencies using `npm ci` (a faster, more reliable version of `npm install` for CI), and finally run the tests.